#include "CCinematicCommand.h"
#include "CSceneObject.h"
#include "CCinematicThread.h"
#include "ClevelEditor.h"
#include "IFileSystem.h"
#include "ISceneManager.h"
#include "ISceneNode.h"
#include "IrrlichtDevice.h"

extern CLevelEditor* editor;

//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
CCinematicCommand::CCinematicCommand()
{	
	m_Name = "";
	
	m_Attributes = g->device->getFileSystem()->createEmptyAttributes();
}
//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
CCinematicCommand::CCinematicCommand( const CCinematicCommand& cmd)
{	
	m_Name = stringw(cmd.m_Name);
	m_time = cmd.m_time;
	m_id = cmd.m_id;
	m_Attributes = g->device->getFileSystem()->createEmptyAttributes();
	editor->copyAttributes(m_Attributes , cmd.m_Attributes);	
}
//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
CCinematicCommand::~CCinematicCommand()
{
	m_Attributes->clear();
	m_Attributes->drop();
}
//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
void CCinematicCommand::CalculateTime(CCinematicThread *pThread)
{
	//m_time = 0;

	//if (m_Name == "SetAnim")
	//{
	//	stringc str = m_Attributes->getAttributeAsString("$Anim");
	//	if (pThread->m_Obj->m_timelineController)
	//	{
	//		int animIndex = pThread->m_Obj->m_timelineController->getClipIndex(str.c_str());
	//		m_time = pThread->m_Obj->GetCurrentAnimationTime(animIndex);
	//	}
	//}
	//else if (m_Name == "FollowWayPoint")
	//{
	//	int wpID = m_Attributes->getAttributeAsInt("^ID^WayPoint");
	//	float speed = m_Attributes->getAttributeAsFloat("Speed");

	//	CSceneObject *pObj = editor->getSceneObjectFromID(wpID);
	//	
	//	if (pObj)
	//	{
	//		float distance = (pThread->m_Obj->m_SceneNode->getAbsolutePosition() - pObj->m_SceneNode->getAbsolutePosition()).getLength();

	//		m_time = distance * 1000 / speed;
	//	}
	//}
}
//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
